home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 1 Issue 2
/
PDCD-1 - Issue 02.iso
/
_printapps
/
printapps
/
_oneprint
/
!ONEPRINT
/
SOURCE
< prev
next >
Wrap
Text File
|
1991-03-29
|
29KB
|
963 lines
REM >Source
REM Program One Print
REM Version 1.00
REM Author Geoff Titmuss
REM ⌐ Ivoryash Limited 1991
REM Program Subject to Copyright
ver$ = "1.00 (1 April 1991)"
ON ERROR VDU4:PRINT REPORT$;" at line ";ERL;" - press a key":in=GET:PROCstop
REM To add a new printer, increment Makes by 1, and add an extra initial
REM value on the line Makes()=...
REM Then add another IF THEN ... ENDIF block in PROCsetcodes, but with
REM your printer control codes.
Makes=2 :REM number of printer types
DIM Make$(Makes)
Make$()="Star NL10","Cannon BJ10e","Epson FX80"
h%=OPENIN("<Obey$Dir>.Printer") :REM get default printer
Printer$=GET$#h%
CLOSE#h%
L%=0 :REM clear global variable - left margin
R%=0 :REM clear global variable - right margin
lines = 1 :REM number of entry lines on screen
PROCwimp :REM set up wimp environment
REM Main loop *****************************************
ON ERROR PROCerror
REPEAT
SYS "Wimp_Poll",,b TO reason
CASE reason OF
WHEN 2: b!24=0 :REM don't allow scroll
SYS "Wimp_OpenWindow",,b :REM Open window request
IF !b=entry: PROCresize
WHEN 3: SYS "Wimp_CloseWindow",,b :REM Close window request
WHEN 6: PROCbuttons(b) :REM Mouse button change
WHEN 7: PROCdragdone :REM User drag box
WHEN 8: PROCkey :REM Key pressed
WHEN 9: PROCmenuselect(b) :REM Menu select
WHEN 17,18:PROCreceive(b) :REM General message
WHEN 19: PROCnoack(b) :REM Request not acknowledged
ENDCASE
UNTIL quit
PROCstop
END
DEF PROCkey :REM handle key presses
IF !b=entry THEN
CASE b!24 OF
WHEN 13 :PROCcaret(b!4, 1, TRUE) :REM return pressed
WHEN &18E :PROCcaret(b!4, 1, FALSE) :REM up arrow
WHEN &18F :PROCcaret(b!4,-1, FALSE) :REM down arrow
ENDCASE
ENDIF
IF !b=saveas AND b!24=13 :PROCsaveit($fname) :REM return on save window
SYS "Wimp_ProcessKey",b!24 :REM pass key on to other apps
ENDPROC
DEF PROCcaret(icon, direction, right) :REM move carrot in window
icon += direction
IF icon > lines-1 :icon = 0 :REM below bottom icon
IF icon < 0 :icon = lines-1 :REM above top icon
IF right=FALSE THEN
SYS "Wimp_GetCaretPosition",,b
right = b!20
ENDIF
right=FNmin(right, LEN( $(FNindir(entry, icon))))
SYS "Wimp_SetCaretPosition",entry,icon,,,-1,right
ENDPROC
REM resize input window - this is not trivial because I choose to
REM put three buttons at the bottom of the screen, because this is
REM easier and more intuitive than menu selection. So, if the
REM window is sized, I have to remove all the icons, and then
REM recreated the correct number of input lines. I then add the new
REM buttons on the bottom. Sorry - it flickers a bit!
DEF PROCresize
SYS "Wimp_GetCaretPosition",,b :REM remember where the carrot was.
CaretWin = !b
CaretIcon = b!4
CaretIndex = b!20
!b = entry :REM find how big the window is.
SYS "Wimp_GetWindowState",,b
miny = b!8
maxy = b!16
sizex = b!12-b!4
sizey = b!16-b!8
ycount = ((sizey-top-bottom) DIV depth) -1 :REM number of input lines.
IF (ycount=lines) AND (oldsizex=sizex): ENDPROC :REM no change in size.
FOR I%=0 TO ClearBox: PROCshut(I%): NEXT :REM delete all icons.
FOR I%=0 TO ycount-1 :REM add new input lines.
temp = top+((I%+2)*depth)
temp = FNopen(TextIcon, sizex-20, -temp, -temp-depth, text+80*I%)
NEXT
temp1 = top + ((ycount+1)*depth) + 65
PrintBox = FNopen(PrintIcon, 0, -temp1, -temp1-Depth, 0)
OptionsBox = FNopen(OptionsIcon, 0, -temp1, -temp1-Depth, 0)
ClearBox = FNopen(ClearIcon, 0, -temp1, -temp1-Depth, 0)
PROCredraw(entry, FALSE) :REM this makes changes visible
lines = ycount :REM number of input lines
oldsizex = sizex :REM remember for next time
IF CaretWin = entry THEN
CaretIcon = FNmin(CaretIcon, lines-1)
SYS "Wimp_SetCaretPosition",entry,CaretIcon,,,-1,CaretIndex
ENDIF
ENDPROC
DEF FNopen(block, maxx, maxy, miny, indir) :REM open an icon
block!8 = miny
IF maxx<>0: block!12 = maxx
block!16 = maxy
IF indir<>0: block!24 = indir :REM point at text buffer
SYS "Wimp_CreateIcon" ,,block TO temp
=temp
DEF PROCshut(icon) :REM shut an icon
!b = entry
b!4 = icon
SYS "Wimp_DeleteIcon",,b
ENDPROC
REM ***********
REM
REM MenuSelect
REM
REM ***********
DEF PROCmenuselect(b)
CASE !b OF
WHEN 1:PROCsaveit($fname) :REM save as
WHEN 2: :REM select another printer
IF b!4 <> -1 THEN
Printer$ = Make$(b!4)
PROCgrey(0) :REM ungray any options for old printer
PROCsetcodes :REM set up new printer codes
PROCgrey(1) :REM gray any options not available
L%=0: R%=0
$SetUpTitle = "Options - "+Printer$
PROCredraw(setup,FALSE) :REM show correct printer in title bar
PROCsaveprinter :REM save printer choice on disk
ENDIF
WHEN 3: PROCexample :REM print test sheet
WHEN 4: quit=TRUE :REM quit
ENDCASE
PROCgetpointer :REM redisplay menu if adjust used
IF buttons% AND 1 THEN
PROCquitmenu(X%,Y%)
ENDIF
ENDPROC
DEF PROCsaveprinter :REM save current printer choice on disk
ON ERROR LOCAL: ENDPROC :REM if problem - forget it!
h%=OPENOUT("<Obey$Dir>.Printer")
BPUT#h%,Printer$+CHR$(10)
CLOSE#h%
ENDPROC
REM ********
REM
REM Buttons
REM
REM ********
DEF PROCbuttons(b)
window = b!12
icon = b!16
buttons = b!8
CASE window OF
WHEN -2 :REM icon bar
IF buttons=&02 THEN
PROCquitmenu(!b-64,298) :REM display menu
ELSE
PROCredraw(setup,TRUE) :REM open options window
PROCredraw(entry,TRUE) :REM open input window
ENDIF
WHEN entry :REM main display
CASE TRUE OF
WHEN buttons=&02 :REM menu button pressed
PROCquitmenu(!b,b!4) :REM display menu
WHEN (buttons=&01 OR buttons=&04) :REM select button pressed
CASE icon OF
WHEN PrintBox
IF FNbuffer=TRUE THEN
PROCmargin(VAL($left),VAL($right))
PROCprintit :REM Print
ENDIF
WHEN OptionsBox
PROCredraw(setup,TRUE) :REM Options
WHEN ClearBox
PROCclear :REM Clear text
PROCredraw(entry, FALSE) :REM refresh display
SYS "Wimp_SetCaretPosition",entry,0,,,-1,-1
ENDCASE
ENDCASE
WHEN setup :REM options window
IF buttons=&02 THEN
PROCquitmenu(!b,b!4) :REM display menu
ELSE
PROCprint(FNsetstyle) :REM send new codes to printer - this
:REM looks good on printers with LEDs
:REM which show their settings.
ENDIF
WHEN saveas :REM save window
CASE TRUE OF
WHEN (icon=dragicon AND (b!8 AND &50)<>0) :REM icon dragged
PROCdragbox
WHEN icon=ok :REM ok pressed
PROCsaveit($fname)
ENDCASE
ENDCASE
ENDPROC
DEF PROCprintit :REM send text to printer
PROCprint(FNsetstyle) :REM send control codes
FOR I%=0 TO lines-1 :REM then print each line directly
word$ = $(FNindir(entry, I%)) :REM from the icon buffer.
PROCprint(word$+nl$)
NEXT
ENDPROC
DEF FNstate(icon) :REM is icon selected?
!b = setup
b!4 = icon
SYS "Wimp_GetIconState",,b
=((b!26 AND %00100000) = %00100000)
DEF PROCclear :REM clear all icon buffers of text.
FOR I%=0 TO 30
$(text+I%*80) = ""
NEXT
ENDPROC
REM ****** FILE TRANSFER *************************
REM
REM 4 cases
REM Me to file - dragbox,dragdone,filesave,saveit
REM File to me - dataload
REM Me to App - dragbox,dragdone,,sendram
REM App to Me - savetous,getram
REM
REM **********************************************
DEF PROCreceive(b)
CASE b!16 OF
WHEN 0: quit=TRUE :REM Shut down
WHEN 1: PROCsavetous(b) :REM Program wishes to save a file
WHEN 2: PROCfilesave(b) :REM Ready to save a file
WHEN 3: PROCdataload(b) :REM Load a file
WHEN 6: PROCsendram(b) :REM Data pipe from me
WHEN 7: PROCgetram(b) :REM Data pipe to me
ENDCASE
ENDPROC
DEF PROCdragbox
!b = saveas :REM window handle
SYS "Wimp_GetWindowState",,b :REM get window position
wex = b!4 - b!20 :REM min x - x scroll
wey = b!16 - b!24 :REM max y - y scroll
b!4 = dragicon :REM icon handle
SYS "Wimp_GetIconState",,b :REM get icon position
b!4 = 5 :REM Drag type - fixed size box
b!8 = b!8 + wex :REM min x of initial box
b!12 = b!12 + wey :REM min y of initial box
b!16 = b!16 + wex :REM max x
b!20 = b!20 + wey :REM max y
b!24 = 0 :REM min x parent
b!28 = 0 :REM min y parent
b!32 = &7FFFFFFF :REM max x parent
b!36 = &7FFFFFFF :REM max y parent
SYS "Wimp_DragBox",,b
newdrag=TRUE :REM note for sendram
ENDPROC
DEF PROCdragdone
length=0 :REM calculate size of text to send.
FOR I%=0 TO lines-1
length+=LEN($(FNindir(entry, I%)))+1
NEXT
SYS "Wimp_GetPointerInfo",,b :REM block is for output
b!20=64 :REM length of block
b!32=0 :REM my ref (0=originating)
b!36=1 :REM message action
b!40=b!12 :REM window handle
b!44=b!16 :REM icon handle
b!48=!b :REM destination x
b!52=b!4 :REM destination y
b!56=length :REM size of file
b!60=&FFF :REM file type
$(b+64)=FNleaf($fname)+CHR$0 :REM file name, zero terminated
SYS "Wimp_SendMessage",17,b+20,b!12,b!16
myref=b!28 :REM myref returned
ENDPROC
DEF PROCfilesave(b) :REM filing system ready to save file.
IF b!12=myref THEN
PROCsaveit(FNgname(b+44))
b!12=b!8 :REM say file saved OK.
b!16=3
SYS "Wimp_SendMessage",18,b,b!4
ENDIF
ENDPROC
DEF PROCsaveit(name$) :REM actually save the file
REM if name contains . it is file name.
REM if name contains < it is a RISC OS variable.
IF INSTR(name$,".") OR INSTR(name$,"<") THEN
$fname = name$ :REM set name for next time
I%=0
X%=OPENOUT name$
FOR I%=0 TO lines-1
word$ = $(FNindir(entry, I%))
BPUT#X%,word$
NEXT
CLOSE #X%
OSCLI("STAMP "+name$) :REM put date on it
OSCLI("SETTYPE "+name$+" &FFF") :REM text file
!b1=saveas :REM window handle
SYS "Wimp_CloseWindow",,b1 :REM close save window
SYS "Wimp_CreateMenu",,-1 :REM close all menus
ELSE
$b1=" To save, drag the icon to a directory viewer"
SYS "Wimp_ReportError",b1,1,"!Teletext"
ENDIF
ENDPROC
DEF PROCdataload(b) :REM load from filing system
PROCclear :REM clear input window of text
ff$=FNgname(b+44) :REM name of file
I%=0
X%=OPENIN ff$
WHILE (NOT EOF#X%) AND (I%<30)
temp$ = GET$#X%
$(text+I%*80) = LEFT$(temp$,80)
I%+=1
ENDWHILE
CLOSE #X%
REM if file was created just for me to load, delete it.
IF b!12=myref: *DELETE <Wimp$Scrap>
b!12=b!8
b!16=4 :REM say file has been loaded.
SYS "Wimp_SendMessage",17,b,b!4
PROCredraw(entry, FALSE) :REM refresh the display.
ENDPROC
REM **************************************************
REM
REM SaveToUs, GetRam - a program wishes to save to us
REM
REM **************************************************
DEF PROCsavetous(b) :REM b from message type 17,18
FOR F%=0 TO 43 STEP 4 :REM record block in case no reply
oldblk!F%=b!F%
NEXT
fname$=FNgname(b+44) :REM file name
flength=b!36 :REM length of file
ftype=b!40 :REM file type
rma=FNclaim(b!36) :REM address of RMA memory
b!12=b!8 :REM my ref?
b!16=6 :REM send it to me as RAM
b!20=rma :REM start address
b!24=b!36 :REM length of block
SYS "Wimp_SendMessage",18,b,b!4
myref=b!12 :REM myref?
retry=TRUE :REM flag in case no reply to message 6
ENDPROC
DEF PROCgetram(b) :REM other app has sent data via RAM
IF b!24=flength THEN
b!12=b!8
b!16=6 :REM message - send it to me as RAM
SYS "Wimp_SendMessage",18,b,b!4
ELSE :REM data has been sent
PROCclear :REM clear input window of text
fname$=FNleaf(fname$) :REM get short file name
I% = 0 :REM loop round data, splitting into new lines
J% = 0 :REM for newline(10) or return(13)
K% = 0
REPEAT
?(text+I%*80+K%) = rma?J%
K%+=1
IF rma?J% = 13: I%+=1: K%=0
IF rma?J% = 10: ?(text+I%*80+K%-1)=13: I%+=1: K%=0
IF K%>78: ?(text+I%*80+K%) = 13: I%+=1: K%=0
J%+=1
UNTIL (I% > 32) OR (J% >= flength)
PROCrelease(rma) :REM release RMA memory
PROCredraw(entry, FALSE) :REM refresh the display
ENDIF
ENDPROC
REM ****************************************************
REM
REM NoAck is run when an app wants to save a file to me
REM but they don't support data pipe
REM
REM ****************************************************
DEF PROCnoack(b) :REM b from type 19 message
IF b!12=myref THEN
IF retry THEN
oldblk!12=oldblk!8
oldblk!16=2 :REM ready to save a file
!oldblk=100
oldblk!36 = -1
$(oldblk+44)="<Wimp$Scrap>"+CHR$0 :REM temp file name
SYS "Wimp_SendMessage",17,oldblk,oldblk!4
myref=oldblk!8
retry=FALSE :REM don't try again
ELSE
ERROR 1,"Pipe Broken"
ENDIF
ENDIF
ENDPROC
REM ****************************************
REM
REM SendRam - an application wants my file
REM
REM ****************************************
DEF PROCsendram(b)
IF newdrag THEN
newdrag=FALSE
rma=FNclaim(length) :REM address of RAM for transfer
ptr=rma :REM put text into block of RAM
FOR I%=0 TO lines-1
temp$=$(FNindir(entry, I%))
$ptr = temp$
ptr+=LEN(temp$)+1
?(ptr-1) = 10
NEXT
start=rma :REM start address of data to send
cnd=start+length :REM end address of data to send
ENDIF
IF b!24 < cnd-start THEN
cend=start+b!24
ELSE
cend=cnd
ENDIF
REM the following line transfers my block of RAM to the other
REM applications block of RAM - I believe!
SYS "Wimp_TransferBlock",us,start,b!4,b!20,cend-start
b!12=b!8
b!16=7 :REM message - load ram
b!24=cend-start :REM amount sent
SYS "Wimp_SendMessage",18,b,b!4
start=cend
IF start=cnd: PROCrelease(rma) :REM release memory
!b1=saveas :REM window handle
SYS "Wimp_CloseWindow",,b1 :REM close save window
SYS "Wimp_CreateMenu",,-1 :REM close all menus
ENDPROC
DEF FNclaim(size) :REM claim an area of RAM
SYS "OS_Module",6,,,size TO ,,ptr
=ptr
DEF PROCrelease(RETURN ptr) :REM release an area of RAM
IF ptr: SYS "OS_Module",7,,ptr
ptr=0
ENDPROC
DEF FNleaf(path$) :REM return short file name (no path)
WHILE INSTR(path$,".")
path$=MID$(path$,INSTR(path$,".")+1)
ENDWHILE
=path$
DEF FNgname(ptr) :REM return zero terminated file name
LOCAL f$
WHILE ?ptr f$+=CHR$?ptr
ptr+=1
ENDWHILE
=f$
REM ******************
REM
REM Error has occured
REM
REM ******************
DEF PROCerror
!b=ERR
$(b+4)=REPORT$+" at line "+STR$ERL+CHR$0
SYS "Wimp_ReportError", b, 3, "!OnePrint" TO ,response%
IF response%=2: PROCstop
ENDPROC
DEF PROCstop :REM close task down neatly.
SYS "Wimp_CloseDown"
END
ENDPROC
REM ***********************************************
REM
REM QuitMenu, Menu, MenuItem, MenuHead build menus
REM
REM ***********************************************
DEF PROCquitmenu(X%,Y%) :REM construct menu
menuflag=0 :REM redundant flag!
P%=FNmenuhead(m,"One Print",200)
P%=FNmenuitem(P%, 0, info,&7000021, "Info",0,0,0)
P%=FNmenuitem(P%, 0,saveas,&7000021, "Save",0,0,0)
P%=FNmenuitem(P%, 0, m1,&7000021, "Printer",0,0,0)
P%=FNmenuitem(P%, 0, -1,&7000021,"Test Printer",0,0,0)
P%=FNmenuitem(P%,&80, -1,&7000021, "Quit",0,0,0)
P%=FNmenuhead(m1,"Printers",200) :REM construct Printer menu
FOR I%=0 TO Makes
flag=0: IF I%=Makes: flag=&80
IF Printer$=Make$(I%): flag=flag EOR &01
P%=FNmenuitem(P%,flag,-1,&7000021,Make$(I%),0,0,0)
NEXT
SYS "Wimp_CreateMenu",,m,X%,Y% :REM blk,x select - 64,y
ENDPROC
DEF FNmenuitem(m,a,b,c,text$,d,e,f)
!m=a :REM menu flags (&80 = last item)
m!4=b :REM sub menu pointer
m!8=c :REM icon flags
IF text$<>"" THEN
$(m+12)=text$ :REM icon data
ELSE
m!12=d :REM pointer to text
m!16=e :REM pointer to validation string
m!20=f :REM length of buffer
ENDIF
=m+24
DEF FNmenuhead(m,text$,width)
$m=text$ :REM menu title
m!12=&70207 :REM colour
m!16=width :REM width of menu items
m!20=40 :REM height of menu items
m!24=0 :REM vertical gap between items
=m+28
DEF PROCgetpointer
SYS "Wimp_GetPointerInfo",,b
mousex% = !b
mousey% = b!4
buttons% = b!8
handle% = b!12
icon% = b!16
ENDPROC
DEF PROCredraw(window,topwin) :REM refresh window on display
IF topwin THEN
!b=window
SYS "Wimp_GetWindowState",,b :REM get size of window
b!28=-1 :REM position window on top
SYS "Wimp_OpenWindow",,b
ENDIF
!b=window
SYS "Wimp_RedrawWindow",,b TO more%
WHILE more%
SYS "Wimp_GetRectangle",,b TO more%
ENDWHILE
ENDPROC
REM ***********************
REM
REM Icon defines all icons
REM
REM ***********************
DEF FNicon(!b,b!4,b!8,b!12,b!16,b!20,text$,d,f)
IF text$<>"" THEN
$(b+24)=LEFT$(text$,12) :REM icon data
ELSE
b!24=d :REM pointer to text
b!28=-1 :REM pointer to validation string
b!32=f :REM length of buffer
ENDIF
SYS "Wimp_CreateIcon",,b TO handle
=handle
DEF FNmax(x%,y%)
IF x%>y% :=x%
=y%
DEF FNmin(x%,y%)
IF y%<x% :=y%
=x%
DEF PROCwimp : REM Set up WIMP environment
DIM b &1000, b1 100, m 400, m1 300
DIM PrintIcon 40, OptionsIcon 40, ClearIcon 40, TextIcon 40
DIM text 3000
$b="TASK"
SYS "Wimp_Initialise",200,!b,"OnePrint" TO ,us
icon=FNicon(-1,0,10,68,78,&3002,"!OnePrint",0,0) :REM put icon on icon bar
quit = FALSE :REM flag to stop
myref = 1234 :REM used in file transfer
DIM oldblk 256 :REM block used in file transfer
retry = FALSE :REM flag for file transfer
REM Load windows from template file *******************
DIM ind% 2000 :REM indirected icon work space
SYS "Wimp_OpenTemplate",,"<Obey$Dir>.Templates"
SYS "Wimp_LoadTemplate",,b,ind%,ind%+2000,-1,"Entry",0 TO ,,ind%
SYS "Wimp_CreateWindow",,b TO entry
SYS "Wimp_LoadTemplate",,b,ind%,ind%+1000,-1,"Info",0 TO ,,ind%
SYS "Wimp_CreateWindow",,b TO info
SYS "Wimp_LoadTemplate",,b,ind%,ind%+1000,-1,"xfer_send",0 TO ,,ind%
SYS "Wimp_CreateWindow",,b TO saveas
SYS "Wimp_LoadTemplate",,b,ind%,ind%+1000,-1,"SetUp",0 TO ,,ind%
SYS "Wimp_CreateWindow",,b TO setup
SYS "Wimp_CloseTemplate"
!b = info :REM set version number
b!4 = 4
SYS "Wimp_GetIconState",,b
$(b!28) = ver$
!b = saveas :REM get filename indirection
b!4 = 1
SYS "Wimp_GetIconState",,b
fname = b!28
$fname = "Textfile"
ok = 0 :REM ok icon number
dragicon = 2 :REM dragicon number
PROCsprite("file_fff") :REM open sprite on saveas window
right=FNindir(setup, 7) :REM indirection for right margin string
left =FNindir(setup, 29) :REM ditto left
PROCsetcodes :REM set up printer codes
PROCgrey(1) :REM gray any unavailable options
!b = setup
SYS "Wimp_GetWindowInfo",,b
SetUpTitle = b!76 :REM indirection of window title
$SetUpTitle = "Options - "+Printer$
!b = entry :REM get initial size of entry window
SYS "Wimp_GetWindowState",,b
miny = b!8
maxy = b!16
oldsizex = 0
lasticon = 0
PROCstore(lasticon, TextIcon) :REM structure for data entry icons
depth = TextIcon!16 - TextIcon!8
top = TextIcon!8
bottom = 127
PrintBox = 1 :REM button icon numbers on
OptionsBox = 2 :REM template file.
ClearBox = 3
PROCstore(PrintBox,PrintIcon) :REM store structure for buttons.
PROCstore(OptionsBox,OptionsIcon)
PROCstore(ClearBox,ClearIcon)
Depth = ClearIcon!16 - ClearIcon!8
PROCclear :REM clear data entry to blank
PROCresize :REM redraw window for initial size
ENDPROC
DEF PROCsprite(temp$) :REM open sprite on saveas window
!b1 = saveas
b1!4 = dragicon
SYS "Wimp_GetIconState",,b1
!b = saveas
b!4 = dragicon
SYS "Wimp_DeleteIcon",,b
b1!4 = saveas
b1?24 = &02
b1?25 = &60
$(b1+28) = temp$+CHR$(13)
SYS "Wimp_CreateIcon",,b1+4
ENDPROC
DEF PROCstore(icon, RETURN block) :REM store an icon structure in block
!block = entry
block!4 = icon
SYS "Wimp_GetIconState",,block
block!4 = entry
block = block+4
ENDPROC
DEF FNindir(window, icon) :REM find indirected string address
!b1 = window
b1!4 = icon
SYS "Wimp_GetIconState",,b1
=b1!28
DEF PROCmargin(left%, right%) :REM send printer codes for left and
:REM right margins. Only send them
:REM if margins have changed, since some
:REM printers need a line feed to activate
:REM this! eg Cannon BJ-10e
IF (L%<>left%) OR (R%<>right%) THEN
L%=left%
R%=right%
IF Margin$="" THEN
PROCprint(LMargin$+CHR$(L%))
PROCprint(RMargin$+CHR$(R%))
ELSE
PROCprint(Margin$+CHR$(L%)+CHR$(R%)+nl$)
ENDIF
ENDIF
ENDPROC
DEFFNsetstyle :REM Set printer codes
P$ = Reset$
IF FNstate(22) :P$+=NLQOn$
IF FNstate(9) :P$+=ExpandOn$
IF FNstate(10) :P$+=EliteOn$+ExpandOn$
IF FNstate(12) :P$+=EliteOn$
IF FNstate(13) :P$+=CondenseOn$
IF FNstate(14) :P$+=EliteOn$+CondenseOn$
IF FNstate(16) :P$+=EmphOn$
IF FNstate(17) :P$+=BoldOn$
IF FNstate(18) :P$+=EmphOn$+BoldOn$
IF FNstate(20) :P$+=ItalicOn$
IF FNstate(24) :P$+=SuperOn$
IF FNstate(25) :P$+=SubOn$
IF FNstate(27) :P$+=DoubOn$
IF FNstate(28) :P$+=QuadOn$
IF FNstate(31) :P$+=Centre$
IF FNstate(8) :P$+=Right$
=P$
DEF PROCgrey(OnOff)
IF EmphOn$="" :PROCgreyicon(16): PROCgreyicon(18)
IF BoldOn$="" :PROCgreyicon(17): PROCgreyicon(18)
IF ItalicOn$="" :PROCgreyicon(19): PROCgreyicon(20)
IF NLQOn$="" :PROCgreyicon(21): PROCgreyicon(22)
IF DoubOn$="" :PROCgreyicon(26): PROCgreyicon(27)
IF QuadOn$="" :PROCgreyicon(28)
IF Left$="" :PROCgreyicon(30):PROCgreyicon(31):PROCgreyicon(8)
ENDPROC
DEF PROCgreyicon(icon)
!b = setup
b!4 = icon
IF OnOff=1 THEN
b!8 = %10000000000000000000000
ELSE
b!8 = %00000000000000000000000
ENDIF
b!12 = %10000000000000000000000
SYS "Wimp_SetIconState",,b
ENDPROC
DEF PROCprint(a$) :REM send text to printer
*FX3,10
*FX6,254
PRINT a$;
*FX6,10
*FX3,0
ENDPROC
DEF FNbuffer :REM printer on?
IF FNprinterOn: =TRUE
REPEAT
!b=30
$(b+4)="Printer not ready"
SYS "Wimp_ReportError", b, 3, "!OnePrint" TO ,response%
IF response%=2: =FALSE :REM user cancelled
REM clear printer buffer (Cannon BJ10e seems to need this?)
*FX21,3
UNTIL FNprinterOn
=TRUE
DEF FNprinterOn
startsize=ADVAL(-4)
*FX3,10
VDU 0,0 :REM send a null code.
*FX3,0
time=TIME+5:REPEAT UNTIL TIME>time :REM allow some time for printer
endsize=ADVAL(-4) :REM to swallow data.
IF endsize>=startsize: =TRUE
=FALSE
DEFFNchr(a%,b%,c%) :REM contruct a string of control codes
IF c%=-1 AND b%=-1: =CHR$(a%)
IF c%=-1:=CHR$(a%)+CHR$(b%)
=CHR$(a%)+CHR$(b%)+CHR$(c%)
DEFPROCexample :REM example text
PROCmargin(0,80) :REM set margins to full width
T$="This is ":I$=" characters per inch)"
IF FNbuffer=FALSE: ENDPROC
PROCprint(Reset$+ExpandOn$+T$+"expanded Pica (5 per inch)"+nl$)
PROCprint(Reset$+EliteOn$+ExpandOn$+T$+"expanded Elite (6 per inch)"+nl$)
PROCprint(Reset$+T$+"Pica (10"+I$+nl$)
PROCprint(Reset$+EliteOn$+T$+"Elite (12"+I$+nl$)
PROCprint(Reset$+CondenseOn$+T$+"condensed Pica (17"+I$+nl$)
PROCprint(Reset$+EliteOn$+CondenseOn$+T$+"condensed Elite (20"+I$+nl$)
PROCprint(Reset$+nl$)
PROCprint(Reset$+T$+"single strike"+nl$)
PROCprint(Reset$+EmphOn$+T$+"emphasized printing"+nl$)
PROCprint(Reset$+BoldOn$+T$+"bold printing"+nl$)
PROCprint(Reset$+EmphOn$+T$+"emphasized and bold"+nl$)
PROCprint(Reset$+nl$)
IF ItalicOn$<>"" :PROCprint(Reset$+ItalicOn$+T$+"italic style"+nl$)
PROCprint(Reset$+NLQOn$+T$+"NLQ (Near letter quality)"+nl$)
IF ItalicOn$<>"" :PROCprint(Reset$+NLQOn$+ItalicOn$+T$+"NLQ in italic style"+nl$)
PROCprint(Reset$+nl$)
PROCprint(Reset$+T$+"normal ")
PROCprint(SuperOn$+T$+"superscript ")
PROCprint(SubOn$+T$+"subscript"+nl$)
PROCprint(Reset$+CondenseOn$+T$+"condensed ")
PROCprint(SuperOn$+T$+"superscript ")
PROCprint(SubOn$+T$+"subscript"+nl$+nl$)
PROCprint(FNsetstyle) :REM reset to options window
PROCmargin(VAL($left),VAL($right)) :REM reset margins
ENDPROC
DEF PROCsetcodes
REM Set codes for printer
REM -1 means short codes
nl$ =CHR$(13) :REM new line character
PicaOn$ =FNchr(27, 80,-1)
EliteOn$ =FNchr(27, 77,-1)
ExpandOn$ =FNchr(27, 87, 1)
ExpandOff$ =FNchr(27, 87, 0)
CondenseOn$ =FNchr(15, -1,-1)
CondenseOff$ =FNchr(18, -1,-1)
EmphOn$ =FNchr(27, 69,-1)
EmphOff$ =FNchr(27, 70,-1)
BoldOn$ =FNchr(27, 71,-1)
BoldOff$ =FNchr(27, 72,-1)
ItalicOn$ =FNchr(27, 52,-1)
ItalicOff$ =FNchr(27, 53,-1)
NLQOn$ =FNchr(27,120, 1)
NLQOff$ =FNchr(27,120, 0)
SuperOn$ =FNchr(27, 83, 0)
SubOn$ =FNchr(27, 83, 1)
SubOff$ =FNchr(27, 84,-1)
DoubOn$ =FNchr(27,104, 1)
QuadOn$ =FNchr(27,104, 2)
DoubOff$ =FNchr(27,104, 0)
Left$ =FNchr(27, 97, 0)
Centre$ =FNchr(27, 97, 1)
Right$ =FNchr(27, 97, 2)
Margin$ = ""
LMargin$ =FNchr(27,108,-1)
RMargin$ =FNchr(27, 81,-1)
REM you only need to set items that differ from defaults.
IF Printer$ = "Cannon BJ10e" THEN
PicaOn$ =FNchr(27,73,0)
EliteOn$ =FNchr(27,58,-1)
NLQOn$ =FNchr(27,73,2)
NLQOff$ =FNchr(27,73,0)
ItalicOn$ =""
ItalicOff$ =""
DoubOn$ =FNchr(27,91,64)+FNchr(4,0,0)+FNchr(0,34,2)
QuadOn$ =""
DoubOff$ =FNchr(27,91,64)+FNchr(4,0,0)+FNchr(0,17,1)
Margin$ =FNchr(27, 88,-1)
Left$ =""
Centre$ =""
Right$ =""
ENDIF
REM you only need to set items that differ from defaults.
IF Printer$ = "Epson FX80" THEN
Left$ = ""
Centre$ = ""
Right$ = ""
DoubOn$ = ""
QuadOn$ = ""
DoubOff$ = ""
ENDIF
REM most printers have a reset code, however to work on all printers
REM (well the 3 I have tried), it seems better to reset the printer by
REM this long winded method!
Reset$ = DoubOff$ + PicaOn$ + ExpandOff$ + CondenseOff$ + EmphOff$ + BoldOff$ + ItalicOff$ + NLQOff$ + SubOff$ + Left$
ENDPROC